<?php 
class UtilsComponent extends Object	{
	var $name = "Utils";
	var $uses = array('Product', 'Category');
	
	function startup(&$controller)
	{
		$this->controller = $controller;
		App::import('Model', 'Category');
		App::import('Model', 'Product');	
		$this->Category = new Category();
		$this->Product = new Product();
	}
	
	function getCategoryList() {
		$fields  = array('Category.id', 'Category.name');
		$conditions = array('Category.parent_id IS NULL');
		$cats = $this->Category->find('all', array('conditions' => $conditions));
		return $cats;
	}
	
	function getSubCategory($catId) {
		$fields  = array('Category.id', 'Category.name');
		$conditions = array('Category.parent_id' => $catId);
		$cats = $this->Category->find('all', array('conditions' => $conditions));
		return $cats;
	}
	
	function getNewArrivalsProduct($catId) {
		$conditions = array('Product.category_id' => $catId, 'Product.is_active' => 1);
		$products = $this->Product->find('all', array('conditions' => $conditions, 'order' => 'rand()', 'limit' => 4));
		return $products;
	}
	
	function getHotNewRelease($catId) {
		$conditions = array('Product.category_id' => $catId, 'Product.is_active' => 1);
		$products = $this->Product->find('all', array('conditions' => $conditions, 'order' => 'rand()', 'limit' => 4));
		return $products;
	}
	
	function getBestSeller($catId) {
		$conditions = array('Product.category_id' => $catId,'Product.reviews > ' => 500, 'Product.is_active' => 1);
		$products = $this->Product->find('all', array('conditions' => $conditions, 'order' => 'rand()', 'limit' => 4));
		return $products;
	}
	
	function getRecommendProduct($catId) {
		$conditions = array('Product.category_id' => $catId,'Product.rating >=' => 4, 'Product.is_active' => 1);
		$products = $this->Product->find('all', array('conditions' => $conditions, 'order' => 'rand()', 'limit' => 4));
		return $products;
	}
	
	function getTopRateProduct($catId) {
		$conditions = array('Product.category_id' => $catId, 'Product.rating >=' => 4.5, 'Product.is_active' => 1);
		$products = $this->Product->find('all', array('conditions' => $conditions, 'order' => 'rand()', 'limit' => 4));
		return $products;
	}
	
	function isInCyberMonday($catId) {
		$cybers = array('10','11','12','13','14','15','16','17','18','19',
						'20','28','29','30','31','32','33','34','35','36','37','38','39',
						'40','41','42','43', '160', '161','162','163','164', '165', '166', '167', '168', '169',
						'60', '61', '62', '63','65', '66', '67', '68','69', '70', '71', '72','74', '74', '99', '100', '101', '102', '103','104', '105');
		if(in_array($catId, $cybers)) {
			return true;
		}		
		return false;
	}
}
?>